package com.wkh.datastructure.sequencetraversal;

import com.wkh.datastructure.queue.LinkedListQueue;

// 层序遍历
public class SequenceTraversal {
    public static void main(String[] args) {
        //创建二叉树
        TreeNode<Integer> root = new TreeNode<>(1,
                new TreeNode<>(2,
                        new TreeNode<>(4,null,null),
                        new TreeNode<>(5,null,null)),
                new TreeNode<>(3,
                        new TreeNode<>(6,null,null),
                        new TreeNode<>(7,null,null)));
        //创建队列
        LinkedListQueue<TreeNode> queue = new LinkedListQueue<>();
        queue.offer(root);
        while (!queue.isEmpty()){
            TreeNode pool = queue.pool();
            System.out.println(pool);
            if (pool.left != null){
                queue.offer(pool.left);
            }
            if (pool.right != null){
                queue.offer(pool.right);
            }
        }
    }
}
